package com.cie2.janji.services;

import java.util.Date;

import org.chenillekit.quartz.services.JobSchedulingBundle;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;

public class PromiseSchedulerBundle implements JobSchedulingBundle {
	private Trigger trigger;

	private JobDetail jobDetail;

	private final UpdatePromiseJob updatePromiseJob;

	private PromiseEngine promiseEngine;

	public PromiseSchedulerBundle(UpdatePromiseJob updatePromiseJob, PromiseEngine promiseEngine) {
		this.updatePromiseJob = updatePromiseJob;
		this.promiseEngine = promiseEngine;
		createBundle();
	}

	private void createBundle() {

//		trigger = TriggerUtils.makeMinutelyTrigger(5); // fire every 5 minute
//		trigger.setStartTime(TriggerUtils.getEvenMinuteDate(new Date())); // start on the next even minute
		trigger = TriggerUtils.makeDailyTrigger(1, 30); // fire every day 1:30 Am
		trigger.setStartTime(TriggerUtils.getEvenMinuteDate(new Date())); // start on the next even minute
		trigger.setName("myTrigger");

		jobDetail = new JobDetail("myJob", null, UpdatePromiseJob.class);
		jobDetail.getJobDataMap().put("UpdatePromiseJob", updatePromiseJob);
		jobDetail.getJobDataMap().put("promiseEngine", promiseEngine);

		//            trigger.setJobDataMap(jobDetail.getJobDataMap());

	}

	public JobDetail getJobDetail() {
		return jobDetail;
	}

	public String getSchedulerId() {
		return null;
	}

	public Trigger getTrigger() {
		return trigger;
	}
}
